#ifndef BASE_UTILS_TIME_UTIL_H
#define BASE_UTILS_TIME_UTIL_H

#include <chrono>

namespace Base {
namespace Utils {
template <typename Unit = std::chrono::milliseconds>
class PerfTimer {
public:
    PerfTimer() : start_(std::chrono::high_resolution_clock::now()) {}

    // 返回经过的时间，单位由模板参数 Unit 决定
    double Elapsed() const {
        auto end = std::chrono::high_resolution_clock::now();
        return std::chrono::duration<double, typename Unit::period>(end - start_).count();
    }

    // 可选：重置计时器
    void Reset() {
        start_ = std::chrono::high_resolution_clock::now();
    }

private:
    std::chrono::time_point<std::chrono::high_resolution_clock> start_;
};

using PerfTimerS  = PerfTimer<std::chrono::seconds>;        // 秒
using PerfTimerMs = PerfTimer<std::chrono::milliseconds>;   // 毫秒
using PerfTimerUs = PerfTimer<std::chrono::microseconds>;   // 微秒
using PerfTimerNs = PerfTimer<std::chrono::nanoseconds>;    // 纳秒
} // namespace Utils
} // namespace Base

#endif // BASE_UTILS_TIME_UTIL_H